﻿<%@ Page Language="C#" AutoEventWireup="true" CodeFile="ClassCauseTeacher.aspx.cs" Inherits="Base_School_ClassCauseTeacher" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>任课信息配置</title>
    
    <link href="../Common/css/main.css" rel="stylesheet" type="text/css" />    
    <script type="text/javascript" src="../Common/Js/jquery.js"></script>
    <script type="text/javascript" src="../Common/Js/common.js"></script>
    <script type="text/javascript" src="../../Common/js/TableForExport.js"></script>
    <script language="javascript">
        //班级授课信息
        var ClassSubjInfo = new Array();
        //显示内容
        function Onview()
        {
            document.getElementById('btnBind').click();
        }
        //年级变化
        function OnGradeChange()
        {
            var value = event.srcElement.value;
            document.getElementById('textGrade').value = value;
        }
        //保存设置
        function OnSave()
        {

            ClassSubjInfo = new Array();
            var settingTable = document.getElementById('settingTable');
            var k =0;
            for(i=1;i<settingTable.rows.length;i++)
            {
                for(j=1;j<settingTable.rows[i].cells.length;j++)
                {
                    ClassSubjInfo[k] = 
                                    {TeacherID:settingTable.rows[i].cells[j].TeacherID,
                                    ClassID : settingTable.rows[i].cells[j].ClassID,
                                    CauseID : settingTable.rows[i].cells[j].CauseID};
                                    k++;
                }
            }

            PageMethods.DoSave(ClassSubjInfo,function(succ){
                showMassgeBox("提示","设置成功",1,null);
            },function(err){//异步失败
            showMassgeBox("提示","设置失败",1,null); })
        }
        //教师变化
        function teacherChange(obj)
        {
            var value = event.srcElement.value;
            obj.parentElement.TeacherID = value;
        }
        function getGradeLeader(roles,g)
        {
            for(i=0;i<roles.length;i++)
            {
                if(roles[i].RoleID == 7 && roles[i].GreadID == g)
                    return  roles[i].SchoolMark;
            }
            return "";
        }
        function getSubjectLeader(roles,c)
        {
            for(i=0;i<roles.length;i++)
            {
                if(roles[i].RoleID == 6 && roles[i].CauseID == c)
                    return  roles[i].SchoolMark;
            }
            return "";
        }
        function getGradeSubjectLeader(roles,g,c)
        {
            for(i=0;i<roles.length;i++)
            {
                if(roles[i].RoleID == 8 && roles[i].CauseID == c && roles[i].GreadID == g)
                    return  roles[i].SchoolMark;
            }
            return "";
        }
        function getLeaderExcel()
        {
            PageMethods.GetTeacherRoles(function(roles)
                {
                    PageMethods.GetCauses(function(causes)
                        {
                            var leadertable = "<table id='leadertable'>";
                             //第一行
                             leadertable +="<tr>";
                             leadertable +="<td>教学领导</td>";
                             leadertable +="<td>科长</td>";
                             leadertable +="<td>七年级</td>";
                             leadertable +="<td>八年级</td>";
                             leadertable +="<td>九年级</td>";
                             leadertable +="</tr>";
                             //第二行 级长
                             leadertable +="<tr>";
                             leadertable +="<td>级长</td>";
                             leadertable +="<td>备课组长</td>";
                             leadertable +="<td>"+getGradeLeader(roles,7)+"</td>";
                             leadertable +="<td>"+getGradeLeader(roles,8)+"</td>";
                             leadertable +="<td>"+getGradeLeader(roles,9)+"</td>";
                             leadertable +="</tr>";
                             //迭代各个备课组
                             for(j=0;j<causes.length;j++)
                             {
                                leadertable +="<tr>";
                                leadertable +="<td>"+causes[j].CauseName+"</td>";
                                leadertable +="<td>"+getSubjectLeader(roles,causes[j].RID)+"</td>";
                                leadertable +="<td>"+getGradeSubjectLeader(roles,7,causes[j].RID)+"</td>";
                                leadertable +="<td>"+getGradeSubjectLeader(roles,8,causes[j].RID)+"</td>";
                                leadertable +="<td>"+getGradeSubjectLeader(roles,9,causes[j].RID)+"</td>";
                                leadertable +="</tr>";
                                
                             }
                             
                             leadertable += "</table>";
                             document.getElementById("loaddata").innerHTML = leadertable;
                             
                             var cells = GetTableInfo(document.getElementById("leadertable"));
                             
                             PageMethods.GetExcel1(cells,function(result){
                                document.getElementById('downloadf').src = "";
                                document.getElementById('downloadf').src = "../../PostFileBytes.aspx";
                            },function(err){alert(err._message);});
                
                        }
                    );
                }
            );
        }
        function getExcel() {
            var cells = GetTableInfo(document.getElementById("settingTable"));
            if(cells!=null)
            {            
//                for(var i=cells.length;i>0;i--)
//                {
//                    if(cells[i]==null)
//                    {
//                        cells[i]=new Array();
//                    }
//                    for(var j=0;j<cells[i-1].length;j++)
//                    {

//                        cells[i][j] = {Sign: cells[i-1][j].Sign,Text:cells[i-1][j].Text,
//                                    Align:cells[i-1][j].Align,
//                                    Type:cells[i-1][j].Type}
//                        if(i==1)
//                        {
//                            cells[i][j].Sign = cells[i][j].Sign+'h';
//                            cells[i][0].Text = "级/备课组";
//                            for(var p = 1;p<cells[i].length;p++)
//                            {
//                                cells[i][p].Text = "";
//                            }
//                        }
//                    }
//                }
            
            
            
                //行转列
                var cells2 = new Array();
                for(var i=0;i<cells.length;i++)
                {
                    
                    for(var j=0;j<cells[i].length;j++)
                    {
                        if(cells2[j]==null)
                        {
                            cells2[j]=new Array();
                        }
                        cells2[j][i] = cells[i][j];
                    }
                }
                
                for(var i=cells2.length;i>0;i--)
                {
                    if(cells2[i]==null)
                    {
                        cells2[i]=new Array();
                    }
                    for(var j=0;j<cells2[i-1].length;j++)
                    {

                        cells2[i][j] = {Sign: cells2[i-1][j].Sign,Text:cells2[i-1][j].Text,
                                    Align:cells2[i-1][j].Align,
                                    Type:cells2[i-1][j].Type}
                        if(i==1)
                        {
                            cells2[i][j].Sign = cells2[i][j].Sign+'c';
                            cells2[i][0].Text = "班主任";
                            for(var p = 1;p<cells2[i].length;p++)
                            {
                                cells2[i][p].Text = "";
                            }
                        }
                    }
                }
                
//                for(var i=cells2.length;i>0;i--)
//                {
//                    if(cells2[i]==null)
//                    {
//                        cells2[i]=new Array();
//                    }
//                    for(var j=0;j<cells2[i-1].length;j++)
//                    {

//                        cells2[i][j] = {Sign: cells2[i-1][j].Sign,Text:cells2[i-1][j].Text,
//                                    Align:cells2[i-1][j].Align,
//                                    Type:cells2[i-1][j].Type}
//                        if(i==1)
//                        {
//                            cells2[i][j].Sign = cells2[i][j].Sign+'g';
//                            cells2[i][0].Text = "级长";
//                            for(var p = 1;p<cells2[i].length;p++)
//                            {
//                                cells2[i][p].Text = "";
//                            }
//                        }
//                    }
//                }
                
                for(var i=0;i<cells2.length;i++)
                {
                    for(var j=0;j<cells2[i].length;j++)
                    {
                       
                        if(cells2[i][j].Text == "(无)")
                        {
                            cells2[i][j].Text ="";
                        }
                    }
                }
                
//                var cellindes = cells2.length;
//                cells2[cellindes]=new Array();
//                for(var j=0;j<cells2[cellindes-1].length;j++)
//                {

//                    cells2[cellindes][j] = {Sign: cellindes+","+j,Text:"",
//                                Align:"center",
//                                Type:"text"}
//                    if(j==0)
//                    {
//                        
//                        cells2[cellindes][0].Text = "级长";
//                    }
//                }
                cells2[0][0].Text = "班级任职";
                PageMethods.GetExcel(cells2,document.getElementById('textGrade').value,function(result){
                document.getElementById('downloadf').src = "";
                document.getElementById('downloadf').src = "../../PostFileBytes.aspx";
                },function(err){alert(err._message);});
            }
        }
        
    function ShowSet()
    {
        document.getElementById('uploadf').src = "";
        document.getElementById('uploadf').src = "upload.aspx?grade="+document.getElementById('textGrade').value;
        ShowPopForm("upInputPop", "upInputPopTitle","教师导入")   ; 
    }
    function ShowLeaderSet()
    {
        document.getElementById('uploadf').src = "";
        document.getElementById('uploadf').src = "uploadLeader.aspx";
        ShowPopForm("upInputPop", "upInputPopTitle","教学领导导入")   ; 
    }
    function myclose()
    {
        document.getElementById('uploadf').src = "about:blank";
        ClosePopForm('upInputPop');
    }
    function HaveDone(status,msg)
    {

        ClosePopForm('upInputPop');
        if(status==1)
        {
            Onview();
        }
        else
        {
            showMassgeBox("提示",msg,1,null);
        }
    }
    </script>
</head>
<body>
<div style="overflow-y:none;overflow-x:none;height:96%;width:98%;">
    <form id="form1" runat="server">
            <div class="pageBody">
            <div class="mainWarp" style="padding-top:5px;padding-left:5px;" >
                <table >
                <tr>
                <td  style="padding-left:4px;">
                    年级：<select id="gradesel" onchange="OnGradeChange()">
                    
                    </select>
                    <input id="Button1" type="button" value="显示" class="commonBut"    onclick="Onview()"/>
                    <input id="Button2" type="button" value="保存" class="commonBut"    onclick="OnSave()"/>
                    <input id="Button4" type="button" value="导入教学领导" class="commonBut"    onclick="ShowLeaderSet()"/>
                    <input id="Button3" type="button" value="导入班级教师" class="commonBut"    onclick="ShowSet()"/>
                </td>
                <td style="padding-left:10px;">
                    <asp:UpdateProgress ID="UpdateProgress1"  runat="server" AssociatedUpdatePanelID="UpdatePanel1"><progresstemplate><img src="../../Common/images/ajax-loader.gif" /></progresstemplate></asp:UpdateProgress>
                </td>
                </tr>

                </table><div>
                    <asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true">
                    </asp:ScriptManager>
                </div>
                <asp:UpdatePanel ID="UpdatePanel1" runat="server">
                    <ContentTemplate>
                        <asp:Repeater ID="Repeater1" runat="server">
                            <HeaderTemplate>
                            <div id="divTable" style="width:97%;  height:94%; margin:left; overflow: auto;position: relative;">
                                
                                        <%= GetHeader()%>
                            </HeaderTemplate>
                            <ItemTemplate>
                                
                                    <%# GetClassInfo((int)Eval("RID"), Eval("ClsName").ToString())%>
                                
                            </ItemTemplate>
                            <FooterTemplate>
                                </table></div>
                            </FooterTemplate>
                        </asp:Repeater>
                    </ContentTemplate>
                    <Triggers>
                        <asp:AsyncPostBackTrigger ControlID="btnBind" EventName="Click" />
                    </Triggers>
                </asp:UpdatePanel>
                <div style="display:none;">
                  <asp:Button ID="btnBind" runat="server" OnClick="btnBind_Click" Text="btnBind" />
                    <asp:TextBox ID="textGrade" runat="server"></asp:TextBox>
                    
                </div>

            </div>
        </div>
        <div  class="layoutWarp" style="display: none">
        <iframe src="" name="downloadf" id="downloadf" style="height: 80%;width: 95%;overflow-y:auto;overflow-x:none;" frameborder="0"   ></iframe>
         </div>
         <div id="upInputPop" class="layoutWarp" style="display: none; width:380px;height:230px;">
             <div class="title" >
	            <span id="upInputPopTitle"></span>
                <a title="关闭" onclick="return myclose()">关闭</a>
                   
              </div>
            <iframe src="" name="ifram" id="uploadf" style="height: 80%;width: 95%;overflow-y:auto;overflow-x:none;" frameborder="0"   ></iframe>
        
        </div>
    </form>
    </div>
    <div id="loaddata" style="display:none;"><table id="leadertable"></table></div>
</body>
</html>
<script language="javascript">


    <%= GetInit() %>
    Onview();


</script>